/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wli.web.java.db;

import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author wli
 */
public class SpellingStudyHelper {

    Session session = null;

    public SpellingStudyHelper() {
        System.out.println("++++++++++++++++++++SpellingStudyHelper Initial ++++++++++++++aaaaaaaaaaaaaaaaaaaaa+++++++++++");
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }

    public List<SpellingStudy> getSpellingStudyList() {
        System.out.println("++++++++++++++++++++SpellingStudyHelper getSpellingStudyList ++++++++++++++aabbbbbbbbbbbbbbbb+++++++++++");
        List<SpellingStudy> spellingStudyList = null;
        try {
            Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from SpellingStudy");
            spellingStudyList = (List<SpellingStudy>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return spellingStudyList;
    }

    public List<SpellingStudy> getSpellingStudyList(Date date) {
        System.out.println("++++++++++++++++++++SpellingStudyHelper getSpellingStudyList ++++++++++++++aabbbbbbbbbbbbbbbb+++++++++++ pass date=====" + date);
        List<SpellingStudy> spellingStudyList = null;
        try {
            Transaction tx = session.beginTransaction();
            Query q = null;

            if (date == null) {
                q = session.createQuery("from SpellingStudy");
            } else {
                q = session.createQuery("from SpellingStudy where date='" + date+"'");
            }
            spellingStudyList = (List<SpellingStudy>) q.list();
            System.out.println("++++++++++++++++++++SpellingStudyHelper getSpellingStudyList ++++++++++++++++++++++" + spellingStudyList.size());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return spellingStudyList;
    }
}
